package com.vision.world.survey.util;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;

import com.esri.arcgisruntime.mapping.view.DrawStatus;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedEvent;
import com.esri.arcgisruntime.mapping.view.DrawStatusChangedListener;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.vision.world.survey.Interface.OnTouchMapEvent;
import com.vision.world.survey.managers.QueryManager;

/**
 * Created by Administrator on 2017/10/13.
 */

public class MapTools {

    /**
     * 设置地图渲染完成状态的监控
     * @param mapView       地图控件
     * @param progressBar   进图条
     */
    public static void initDrawStatusChanged(final Context context, final MapView mapView,
                                             final ProgressBar progressBar,
                                             final OnTouchMapEvent onTouchMapEvent){
        mapView.addDrawStatusChangedListener(new DrawStatusChangedListener() {
            @Override
            public void drawStatusChanged(DrawStatusChangedEvent drawStatusChangedEvent) {
                if(drawStatusChangedEvent.getDrawStatus() == DrawStatus.IN_PROGRESS){
                    progressBar.setVisibility(View.VISIBLE);
                }else if (drawStatusChangedEvent.getDrawStatus() == DrawStatus.COMPLETED){
                    Log.i("isFreshIdentify","加载 complete");
                    progressBar.setVisibility(View.INVISIBLE);
                    if(CommonUtil.isFreshIdentify && !CommonUtil.isIdentify) {
                        //地图刷新完成后加载附近红线区搜索
                        Log.i("isFreshIdentify","搜索红线区");
                        QueryManager.getInstance().initSelectByLocationBoundary(context, mapView, onTouchMapEvent);
                    }
                }
            }
        });
    }
}
